#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <poll.h>
#include <signal.h>
#include <unistd.h>
#include <fcntl.h>
#define u32 unsigned int
struct key_inf{
	char name[10];
	u32 value;
	u32 irq;
	u32 trig;
};
struct key_inf key_press;
char get_buf[100];
struct pollfd keys_pollfd[2];
int fd;
void key_sighandler_SIGIIO(int sig)
{
	printf("app:---%s---\r\n",__FUNCTION__);
	read(fd, &key_press, sizeof(key_press));
	printf("app:irq=%d  value=%d\r\n",key_press.irq,key_press.value);
}


int main()
{
	int fcntl_flag=0;
	//fd = open("/dev/drv_key0", O_RDWR|O_NONBLOCK);
	fd = open("/dev/drv_key0", O_RDWR);
	if(fd < 0)
	{
		printf("drv_key0 open err\r\n");
		exit(1);
	}
	
	signal(SIGIO, key_sighandler_SIGIIO);//注册信号
	
	 fcntl(fd,F_GETOWN,getpid()); //根据进程获取异步IO所有权
	 fcntl_flag = fcntl(fd,F_GETFD);//获取文件描述符中的标识
	fcntl_flag = fcntl_flag|FASYNC;//加入异步通知标识
	
	fcntl(fd,F_SETFL,fcntl_flag);//将标识从新写入
	fcntl(fd,F_SETOWN,getpid()); //根据进程获取异步IO所有权
	while(1)
	{
		printf("app run\r\n");
		sleep(1);
	}
	close(fd);
}
